home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / untested / tcpip / spaces6.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  1.6 KB  |  61 lines  |  [TEXT/ttxt]

  1. ---<<<
  2.  
  3. module webspaces6
  4. uses scriptx
  5. exports importsomemedia, createTheWindow, createTheBall, startSpaces6
  6. end
  7.  
  8. in module webspaces6
  9.  
  10. -- spaces6.sx
  11. -- demo of bouncing ball in a space, with sound when it hits the wall
  12. -- uses 3 controllers: gravity, movement, bounce
  13.  
  14. function createTheWindow tc -> (
  15.     local win := new window boundary:(new rect x1:0 y1:0  x2:300 y2:300) scale:40 title: tc
  16.     win's x := 40
  17.     win's y := 40
  18.     show win
  19.     -- make stroke brush for win
  20.     win's stroke := new brush color:(new rgbcolor red:255 green:0 blue:0) pattern:blackPattern
  21.     
  22.     -- make fill brush for win
  23.     win's fill := new brush color:(new rgbcolor red:100 green:100 blue:100) pattern:blackPattern
  24.  
  25.     local g := new gravity space:win wholespace: true
  26.     local m := new movement space:win wholespace: true
  27.     local b := new bounce space:win wholespace: true
  28.     win
  29. )
  30.     
  31. --importMedia a audioplayer
  32.  
  33. function importsomemedia tc -> (
  34.     local theStream := getStream theScriptDir "demosnd.aif" @Readable
  35.     local da2 := importMedia theImportExportEngine theStream @sound @aiff @player container: tc
  36.     da2.title := tc
  37.     plug theStream
  38.     da2
  39. )
  40.  
  41. -- create a class that is both a 2dshape and a projectile
  42.  
  43. class ball (TwoDShape, Projectile)
  44. end
  45.  
  46. function createTheBall win da -> (
  47.     local ballcolor := new brush color:(new rgbcolor red:0 green:200 blue:0) pattern:blackPattern
  48.     local shp := new ball target:(new oval x1:0 y1:0 x2:20 y2:20)  fill:ballcolor stroke:undefined
  49.     shp's x := 50;
  50.     shp's y := 50;
  51.     shp's audioPlayer := da
  52.     shp's elasticity := 1
  53.     append win shp
  54.     shp's velocity := (new point x:-8.0 y:4.0)
  55. )
  56.  
  57.  
  58. function startSpaces6 tc -> foreach tc load undefined
  59.  
  60. --->>>
  61.